import React,{Component} from 'react';
import {FlatList,Text} from 'react-native';

export default class Demo13Component extends Component{
   constructor(){
     super();
     this.state = {
       productList:[]
     }
   }

   componentDidMount(){
     setTimeout(()=>{
       //向服务器端请求数据
       fetch("http://172.163.100.139/ajia_code/data/product/list.php")
       .then((response)=>{return response.json()})
       .then((result)=>{
         console.log(result);
         //解决key这个警告的问题
         var nowList = result.data;
         for(var i=0;i<nowList.length;i++){
            nowList[i].key = i;
         }
         //状态的写操作
         this.setState(
           {productList:nowList});
       })
     },1000);
   }

   //info item/index
   showListItem(info){
      return <Text>
       {info.item.title}
      </Text>
   }

   render(){
      return <FlatList 
      renderItem={this.showListItem}
      data={this.state.productList}>
      </FlatList>
   }

}